package models

import "strconv"

type SysUser struct {
	ID
	Username string `json:"username" gorm:"type:varchar(50);not null;comment:用户名"`
	Password string `json:"password" gorm:"type:varchar(255);not null;comment:密码"`
	Mobile   string `json:"mobile" gorm:"type:varchar(11);comment:手机号"`
	Nickname string `json:"nickname" gorm:"type:varchar(50);comment:昵称"`
	Avatar   string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
	Email    string `json:"email" gorm:"type:varchar(50);comment:邮箱"`
	Status   int    `json:"status" gorm:"default:1;comment:状态 1:启用 0:禁用"`
	Remark   string `json:"remark" gorm:"type:varchar(255);comment:备注"`
	Type     int    `json:"type" gorm:"default:2;comment:类型 1:管理员 2:普通用户"`

	Roles []SysRole `json:"roles" gorm:"many2many:sys_user_roles;foreignKey:ID;joinForeignKey:UserId;References:ID;joinReferences:RoleId"`

	Timestamps
	SoftDeletes
}

func (sysUser SysUser) GetUid() string {
	return strconv.Itoa(int(sysUser.ID.ID))
}

// 管理员类型枚举
// 管理员类型枚举
const (
	UserTypeAdmin  = 1 // 管理员
	UserTypeNormal = 2 // 普通用户
)

// 获取用户类型描述
func GetUserTypeDesc(userType int) string {
	switch userType {
	case UserTypeAdmin:
		return "管理员"
	case UserTypeNormal:
		return "普通用户"
	default:
		return "未知类型"
	}
}
